<?php
/**
* Copyright (C)2001-2099 Zeai.cn All rights reserved.
* E-Mail：supdes#qq.com　QQ:797311
* http://www.zeai.cn
* http://www.yzlove.com
* Last update 2021/04/20 by supdes
*/
!function_exists('zeaialone') && exit('forbidden');
require_once ZEAI.'cache/config_up.php';
require_once ZEAI.'sub/zeai_up_func.php';
switch ($submitok){
	//通用tmpB
	case 'ajax_tmp_del':
		$url = str_replace(UP,"",$url);
		if(!empty($url))UP_modFn('adm','del',$url.'|'.smb($url,'b'));
		json_exit(array('flag'=>1,'url'=>$url));
	break;
	case 'ajax_tmpB_up_h5':
		if (ifpostpic($file['tmp_name'])){
			$dbname = setphotodbname('tmp',$file['tmp_name'],$cook_uid.'_');
			if (!up_send($file,$dbname,$_UP['ifwaterimg'],$_UP['upBsize']))json_exit(array('flag'=>0,'msg'=>'图片写入失败'));
			json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname,'_s'=>$dbname));//,'_s'=>$dbname为了兼容ZeaiUP.js
		}else{json_exit(array('flag'=>0,'msg'=>'zeai_tmp_name_error'));}
	break;
	case 'ajax_tmpB_up_wx':
		if (str_len($serverIds) > 15){
			$url="https://api.weixin.qq.com/cgi-bin/media/get?access_token=".wx_get_access_token()."&media_id=".$serverIds;
			$dbname = wx_get_up('tmp',$url,$cook_uid.'_','B');
			json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname,'_s'=>$dbname));//,'_s'=>$dbname为了兼容ZeaiUP.js
		}else{json_exit(array('flag'=>0,'msg'=>'zeai_serverIds_down_error'));}
	break;	
	case 'ajax_tmpB_up_app':
		$file=$_FILES['file'];
		$dbname = setphotodbname('tmp',$file['tmp_name'],$cook_uid.'_');
		if (!up_send($file,$dbname,$_UP['ifwaterimg'],$_UP['upBsize']))json_exit(array('flag'=>0,'msg'=>'图片写入失败'));
		json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname,'_s'=>$dbname));	//,'_s'=>$dbname为了兼容ZeaiUP.js
	break;
	case 'ajax_tmpB_up_cut':
		if(empty($base64img) || empty($dbname))json_exit(array('flag'=>0,'msg'=>'上传失败'));
		$base64img = str_replace('data:image/jpeg;base64,','', $base64img);
		$base64img = base64_decode($base64img);
		cut_up($dbname,$base64img);
		json_exit(array('flag'=>1,'msg'=>'裁切成功','_cut'=>$dbname));
	break;
	//reg_diy.php
	case 'ajax_photo_s_tmp_up_h5':
		if (ifpostpic($file['tmp_name'])){
			$dbname = setphotodbname('tmp',$file['tmp_name'],$cook_uid.'_');
			if (!up_send($file,$dbname,$_UP['ifwaterimg'],$_UP['upSsize'],$_UP['upBsize'],$_UP['upMsize']))json_exit(array('flag'=>0,'msg'=>'图片写入失败'));
			$_s = setpath_s($dbname);
			json_exit(array('flag'=>1,'msg'=>'上传成功','_s'=>$_s));
		}else{
			json_exit(array('flag'=>0,'msg'=>'zeai_tmp_name_error'));
		}
	break;
	case 'ajax_photo_s_tmp_up_wx':
		if (str_len($serverIds) > 15){
			$url="https://api.weixin.qq.com/cgi-bin/media/get?access_token=".wx_get_access_token()."&media_id=".$serverIds;
			$dbname = wx_get_up('tmp',$url,$cook_uid.'_','SMB');
			$_s = setpath_s($dbname);
			@up_send_userdel(smb($_s,'blur'),$delvar);
			json_exit(array('flag'=>1,'msg'=>'上传成功','_s'=>$_s));
		}else{
			json_exit(array('flag'=>0,'msg'=>'zeai_serverIds_down_error'));
		}
	break;
	case 'ajax_photo_s_tmp_up_app':
		$f=$_FILES['file'];
		$dbname = setphotodbname('tmp',$file['tmp_name'],$cook_uid.'_');
		if (!up_send($f,$dbname,$_UP['ifwaterimg'],$_UP['upSsize'],$_UP['upBsize'],$_UP['upMsize']))json_exit(array('flag'=>0,'msg'=>'图片写入失败'));
		$_s = setpath_s($dbname);
		json_exit(array('flag'=>1,'msg'=>'上传成功','_s'=>$_s));
	break;
	//my_info.php
	case 'ajax_weixin_pic_tmp_up_h5':
		if (ifpostpic($file['tmp_name'])){
			$dbname = setphotodbname('tmp',$file['tmp_name'],$cook_uid.'_wxpic_');
			if (!up_send($file,$dbname,0,$_UP['upBsize']))json_exit(array('flag'=>0,'msg'=>'图片写入失败'));
			$newpic = $_ZEAI['up2']."/".$dbname;
			if (!ifpic($newpic))json_exit(array('flag'=>0,'msg'=>'图片格式错误'));
			//
			//$row = $db->ROW(__TBL_USER__,"weixin_pic","id=".$cook_uid,"num");
			//if ($row)$data_weixin_pic= $row[0];
			//if(!empty($data_weixin_pic))@up_send_userdel($data_weixin_pic);
			//
			//$db->query("UPDATE ".__TBL_USER__." SET weixin_pic='$dbname' WHERE id=".$cook_uid);
			json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname));
		}else{
			json_exit(array('flag'=>0,'msg'=>'zeai_tmp_name_error'));
		}
	break;
	case 'ajax_weixin_pic_tmp_up_wx':
		if (str_len($serverIds) > 15){
			$serverIds = explode(',',$serverIds);
			$totalN = count($serverIds);
			if ($totalN >= 1){
				foreach ($serverIds as $value) {
					$url="https://api.weixin.qq.com/cgi-bin/media/get?access_token=".wx_get_access_token()."&media_id=".$value;
					$dbname = wx_get_up('tmp',$url,$cook_uid.'_wxpic_','B');
				}
				$newpic = $_ZEAI['up2']."/".$dbname;
				if (!ifpic($newpic))json_exit(array('flag'=>0,'msg'=>'图片格式错误'));
				//$db->query("UPDATE ".__TBL_USER__." SET weixin_pic='$dbname' WHERE id=".$cook_uid);
				//
				//$row = $db->ROW(__TBL_USER__,"weixin_pic","id=".$cook_uid,"num");
				//if ($row)$data_weixin_pic= $row[0];
				//if(!empty($data_weixin_pic))@up_send_userdel($data_weixin_pic);
				//
				json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname));
			}
		}else{
			json_exit(array('flag'=>0,'msg'=>'zeai_serverIds_down_error'));
		}
	break;
	case 'ajax_weixin_pic_tmp_up_app':
		$file=$_FILES['file'];
		$dbname = setphotodbname('tmp',$file['tmp_name'],$cook_uid.'_wxpic_');
		if (!up_send($file,$dbname,0,$_UP['upBsize']))json_exit(array('flag'=>0,'msg'=>'图片写入失败'));
		$newpic = $_ZEAI['up2']."/".$dbname;
		if (!ifpic($newpic))json_exit(array('flag'=>0,'msg'=>'图片格式错误'));
		json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname));
	break;
	/****************my_photo.php****************/
	case 'ajax_photo_up_h5':
		$chkok=chkVPmaxNumFlag('photo');
		if (ifpostpic($file['tmp_name'])  && $chkok){
			$dbname = setphotodbname('photo',$file['tmp_name'],$cook_uid.'_');
			if (!up_send($file,$dbname,$_UP['ifwaterimg'],$_UP['upSsize'],$_UP['upBsize']))json_exit(array('flag'=>0,'msg'=>'图片写入失败'));
			$_s = setpath_s($dbname);
			$flag  = ($switch['sh']['photo_'.$cook_grade] == 1)?1:0;
			$db->query("INSERT INTO ".__TBL_PHOTO__." (uid,path_s,flag,addtime) VALUES ($cook_uid,'$_s',$flag,".ADDTIME.")");
			json_exit(array('flag'=>1,'msg'=>'上传成功'));
		}else{
			json_exit(array('flag'=>0,'msg'=>'zeai_cn_tmp_name_error'));
		}
	break;
	case 'ajax_photo_up_app':
		$file=$_FILES['file'];
		$chkok=chkVPmaxNumFlag('photo');
		if ($chkok){
			$dbname = setphotodbname('photo',$file['tmp_name'],$cook_uid.'_');
			if (!up_send($file,$dbname,$_UP['ifwaterimg'],$_UP['upSsize'],$_UP['upBsize']))json_exit(array('flag'=>0,'msg'=>'图片写入失败'));
			$_s = setpath_s($dbname);
			$flag  = ($switch['sh']['photo_'.$cook_grade] == 1)?1:0;
			$db->query("INSERT INTO ".__TBL_PHOTO__." (uid,path_s,flag,addtime) VALUES ($cook_uid,'$_s',$flag,".ADDTIME.")");
			json_exit(array('flag'=>1,'msg'=>'上传成功'));
		}else{
			json_exit(array('flag'=>0,'msg'=>'zeai_cn_tmp_name_error','path'=>$file['tmp_name'],'chkok'=>$chkok));
		}
	break;
	case 'ajax_photo_up_wx':
		if (str_len($serverIds) > 15){
			$serverIds = explode(',',$serverIds);
			$curTotalN = count($serverIds);
			$chkok  = chkVPmaxNumFlag('photo',($curTotalN-1));
			if ($curTotalN >= 1 && $chkok){
				foreach ($serverIds as $value) {
					$url="https://api.weixin.qq.com/cgi-bin/media/get?access_token=".wx_get_access_token()."&media_id=".$value;
					$dbname = wx_get_up('photo',$url,$cook_uid.'_','SB');
					$_s = setpath_s($dbname);
					$flag  = ($switch['sh']['photo_'.$cook_grade] == 1)?1:0;
					$db->query("INSERT INTO ".__TBL_PHOTO__." (uid,path_s,flag,addtime) VALUES ($cook_uid,'$_s',$flag,".ADDTIME.")");
				}
				json_exit(array('flag'=>1,'msg'=>'上传成功'));
			}
		}else{
			json_exit(array('flag'=>0,'msg'=>'zeai_cn_serverIds_down_error'));
		}
	break;
	/****************my_video.php****************/
	case 'ajax_video_up':
		$chkok=chkVPmaxNumFlag('video');
		if (ifpostpic($file['tmp_name'])  && $chkok){
			$dbname = setVideoDBname('v',$cook_uid.'_',$extname);
			if (!up_send($file,$dbname,'WWW','ZEAI','CN','supdesQQ797311','video')){
				json_exit(array('flag'=>0,'msg'=>'zeai_move_video_error'));
			}else{
				$_s = str_replace('.'.$extname,'.jpg',$dbname);
				$flag  = ($switch['sh']['video_'.$cook_grade] == 1)?1:0;
				$db->query("INSERT INTO ".__TBL_VIDEO__." (uid,path_s,flag,addtime) VALUES ($cook_uid,'$_s',$flag,".ADDTIME.")");
				json_exit(array('flag'=>1,'msg'=>'上传成功'));
			}
		}else{
			json_exit(array('flag'=>0,'msg'=>'zeai_tmp_name_error'));
		}
	break;
	case 'ajax_video_up_app':
		$file=$_FILES['file'];
		$f_name=$_FILES['file']['name'];
		$extname=substr($f_name,-3);
		$chkok=chkVPmaxNumFlag('video');
		if ($chkok){
			$dbname = setVideoDBname('v',$cook_uid.'_',$extname);
			if (!up_send($file,$dbname,'WWW','ZEAI','CN','supdesQQ797311','video')){
				json_exit(array('flag'=>0,'msg'=>'zeai_move_video_error'));
			}else{
				$_s = str_replace('.'.$extname,'.jpg',$dbname);
				$flag  = ($switch['sh']['video_'.$cook_grade] == 1)?1:0;
				$db->query("INSERT INTO ".__TBL_VIDEO__." (uid,path_s,flag,addtime) VALUES ($cook_uid,'$_s',$flag,".ADDTIME.")");
				json_exit(array('flag'=>1,'msg'=>'上传成功','ps'=>$dbname,'tp'=>$extname));
			}
		}else{
			json_exit(array('flag'=>0,'msg'=>'zeai_tmp_name_error'));
		}
	break;
	/****************my_cert.php****************/
	case 'ajax_sfz_up_h5':
		if (ifpostpic($file['tmp_name'])){
			$dbname = setphotodbname('tmp',$file['tmp_name'],$cook_uid.'_RZ_');
			if (!up_send($file,$dbname,0,$_UP['upBsize']))json_exit(array('flag'=>0,'msg'=>'图片写入失败'));
			json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname));
		}else{json_exit(array('flag'=>0,'msg'=>'zeai_tmp_name_error'));}
	break;
	case 'ajax_sfz_up_wx':
		if (str_len($serverIds) > 15){
			$url="https://api.weixin.qq.com/cgi-bin/media/get?access_token=".wx_get_access_token()."&media_id=".$serverIds;
			$dbname = wx_get_up('tmp',$url,$cook_uid.'_RZ_','B');
			json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname));
		}else{json_exit(array('flag'=>0,'msg'=>'zeai_serverIds_down_error'));}
	break;	
	case 'ajax_sfz_up_app':
		$file=$_FILES['file'];
		$dbname = setphotodbname('tmp',$file['tmp_name'],$cook_uid.'_RZ_');
		if (!up_send($file,$dbname,0,$_UP['upBsize']))json_exit(array('flag'=>0,'msg'=>'图片写入失败'));
		json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname));	
	break;
	case 'ajax_certphoto_up_h5':
		if (ifpostpic($file['tmp_name'])){
			$dbname = setphotodbname('tmp',$file['tmp_name'],$cook_uid.'_RZ_');
			if (!up_send($file,$dbname,0,$_UP['upBsize']))json_exit(array('flag'=>0,'msg'=>'图片写入失败'));
			json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname));
		}else{json_exit(array('flag'=>0,'msg'=>'zeai_tmp_name_error'));}
	break;
	case 'ajax_certphoto_up_wx':
		if (str_len($serverIds) > 15){
			$url="https://api.weixin.qq.com/cgi-bin/media/get?access_token=".wx_get_access_token()."&media_id=".$serverIds;
			$dbname = wx_get_up('tmp',$url,$cook_uid.'_RZ_','B');
			json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname));
		}else{json_exit(array('flag'=>0,'msg'=>'zeai_serverIds_down_error'));}
	break;
	case 'ajax_certphoto_up_app':
		$file=$_FILES['file'];
		$dbname = setphotodbname('tmp',$file['tmp_name'],$cook_uid.'_');
		if (!up_send($file,$dbname,0,$_UP['upBsize']))json_exit(array('flag'=>0,'msg'=>'图片写入失败'));
		json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname));
	break;
	/****************315.php****************/
	case 'ajax_315_up_h5':
		if (ifpostpic($file['tmp_name'])){
			$dbname = setphotodbname('tmp',$file['tmp_name'],$cook_uid.'_315_');
			if (!up_send($file,$dbname,0,$_UP['upBsize']))json_exit(array('flag'=>0,'msg'=>'图片写入失败'));
			json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname));
		}else{json_exit(array('flag'=>0,'msg'=>'zeai_tmp_name_error'));}
	break;
	case 'ajax_315_up_wx':
		if (str_len($serverIds) > 15){
			$url="https://api.weixin.qq.com/cgi-bin/media/get?access_token=".wx_get_access_token()."&media_id=".$serverIds;
			$dbname = wx_get_up('tmp',$url,$cook_uid.'_315_','B');
			json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname));
		}else{json_exit(array('flag'=>0,'msg'=>'zeai_serverIds_down_error'));}
	break;	
	case 'ajax_315_up_app':
		$file=$_FILES['file'];
		$dbname = setphotodbname('tmp',$file['tmp_name'],$cook_uid.'_315_');
		if (!up_send($file,$dbname,0,$_UP['upBsize']))json_exit(array('flag'=>0,'msg'=>'图片写入失败'));
		json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname));	
	break;
	case 'ajax_crm_tmp_sb_up':
		if (ifpostpic($file['tmp_name'])){
			$dbname = setphotodbname('tmp',$file['tmp_name'],'');
			if (!up_send($file,$dbname,0,$_UP['upMsize'],$_UP['upBsize']))json_exit(array('flag'=>0,'msg'=>'图片写入失败'));
			$dbname=setpath_s($dbname);
			json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname));
		}else{
			json_exit(array('flag'=>0,'msg'=>'ajax_crm_tmp_sb_up_error'));
		}
	break;
	/*adm up*/
	case 'adm_ajax_video_up':
		if (ifpostpic($file['tmp_name'])){
			$dbname = setVideoDBname('v','crm_',$extname);
			if (!up_send($file,$dbname,'WWW','ZEAI','CN','supdesQQ797311','audio'))json_exit(array('flag'=>0,'msg'=>'zeai_move_video_error'));
			json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname));
		}else{
			json_exit(array('flag'=>0,'msg'=>'zeai_tmp_name_error'));
		}
	break;
}
function chkVPmaxNumFlag($type,$curTotalN=0){
	global $db,$_VIP,$cook_uid,$cook_grade;
	if ($type=='video'){
		$cfgARR=$_VIP['video_num'];
		$tbname=__TBL_VIDEO__;
		$dw='个';
	}elseif($type=='photo'){
		$cfgARR=$_VIP['photo_num'];
		$tbname=__TBL_PHOTO__;
		$dw='张';
	}
	$NUM=json_decode($cfgARR,true);$cfgMaxnum = $NUM[$cook_grade];
	$data_num = $db->COUNT($tbname,"uid=".$cook_uid);
	if (($curTotalN+$data_num)>=$cfgMaxnum){json_exit(array('flag'=>0,'msg'=>utitle($cook_grade).'最多上传'.$cfgMaxnum.$dw));}else{
		return true;
	}
}
?>